﻿using System;
using Phone7.Fx;

namespace Wp7nl.Utilities
{
    /// <summary>
    /// Wrapper around the Phone7Fx that writes an object to cache
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class CachingHelper<T> where T :class
    {
        private readonly string _cachekey;

        public CachingHelper(string cachekey)
        {
            this._cachekey = cachekey;
        }
        public T GetFromCache() 
        {
            return Cache.Current.Get<T>(_cachekey);
        }
        
        public void SaveToCache(object objectToSave)
        {
            Cache.Current.Add(_cachekey, objectToSave, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration);
        }

        public void SaveToCache(object objectToSave, TimeSpan slidingExpiration)
        {
            Cache.Current.Add(_cachekey, objectToSave, Cache.NoAbsoluteExpiration, slidingExpiration);
        }
    }
}
